﻿using crm_core;
using crm_data;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;

namespace crm_web
{
    public class DbInitializer
    {
        public static void Initialize(SqlServerDbContext context)
        {
            if (context.Customers.Any())
            {
                return;
            }

            var customers = new Customer[]
            {
                new Customer{
                    RealName ="张三丰",
                    Sex =SexEnum.Male,
                    Birthday =DateTime.Now,
                    PhoneNumber ="13893184271",
                    ContactNumber ="09312619008",
                    CutomerState =0,
                    DelFlag =false,
                    CreateTime =DateTime.Now,
                    UpdateTime =DateTime.Now
                },
                new Customer{
                    RealName ="郭靖",
                    Sex =SexEnum.Male,
                    Birthday =DateTime.Now,
                    PhoneNumber ="13893184272",
                    ContactNumber ="09312619008",
                    CutomerState =0,
                    DelFlag =false,
                    CreateTime =DateTime.Now,
                    UpdateTime =DateTime.Now
                },
            };

            context.Customers.AddRange(customers);
            context.SaveChanges();
            //using (var context = new SqlServerDbContext(serviceProvider.GetRequiredService<DbContextOptions<SqlServerDbContext>>()))
            //{
            //    if (context.Customers.Any())
            //    {
            //        return;
            //    }

            //    var customers = new Customer[]
            //    {
            //    new Customer{
            //        RealName ="张三丰",
            //        Sex =SexEnum.Male,
            //        Birthday =DateTime.Now,
            //        PhoneNumber ="13893184271",
            //        ContactNumber ="09312619008",
            //        CutomerState =0,
            //        DelFlag =false,
            //        CreateTime =DateTime.Now,
            //        UpdateTime =DateTime.Now
            //    },
            //    new Customer{
            //        RealName ="郭靖",
            //        Sex =SexEnum.Male,
            //        Birthday =DateTime.Now,
            //        PhoneNumber ="13893184272",
            //        ContactNumber ="09312619008",
            //        CutomerState =0,
            //        DelFlag =false,
            //        CreateTime =DateTime.Now,
            //        UpdateTime =DateTime.Now
            //    },
            //    };

            //    context.Customers.AddRange(customers);
            //    context.SaveChanges();
            //}
        }
    }
}
